//
//  WineCategoryVC.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/12/5.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "WineCategoryVC.h"
#import "MyAllOrderListVC.h"
#import "MarketHomeController.h"
#import "GoodsCategoryListVC.h"
#import "ShopCarController.h"
#import "MeViewController.h"
#import "OrderSureFirstVC.h"
@interface WineCategoryVC ()


@end

@implementation WineCategoryVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    if (@available(iOS 11.0, *)) {
        self.navigationItem.largeTitleDisplayMode =  UINavigationItemLargeTitleDisplayModeNever;
    }
    
    
    if ([self.type isEqualToString:@"wine"]) {
        self.navigationItem.title = @"商城";
        
        [self setNav];
        
//        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"shopCar"] style:UIBarButtonItemStylePlain target:self action:@selector(jumpSharCar)];
        
    }else{
        
        self.navigationItem.title = @"我的订单";
        [self setNav2];

    }

    // 3.添加子控制器
    [self setupAllChildViewController];
    // Do any additional setup after loading the view.
}





- (void)setNav{
    
    
    //    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(login)];
    
    UIView *navRit = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 42, 36)];
    
    navRit.backgroundColor = [UIColor clearColor];
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(17, 0, 25, 36)];
    
//    imageView.backgroundColor = [UIColor purpleColor];
    
    
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    
    
    imageView.image = [UIImage imageNamed:@"shopCar"];
    
    UILabel *conutLabel = [[UILabel alloc]initWithFrame:CGRectMake(38, 5, 8, 8)];
    
    //    UILabel *conutLabel = [[UILabel alloc]initWithFrame:CGRectMake(36, 3, 20, 14)];
    
    conutLabel.font = MYFONT(11);
    
    conutLabel.backgroundColor = [UIColor redColor];
    
    conutLabel.textColor = [UIColor whiteColor];
    
    conutLabel.layer.masksToBounds = YES;
    
    conutLabel.layer.cornerRadius = 4;
    
    //    conutLabel.text = @"8";
    
    conutLabel.textAlignment = NSTextAlignmentCenter;
    
    myViewModel.shopCarIdetLabel = conutLabel;
    
//    conutLabel.hidden = YES;
    
    UIButton *jumpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    jumpBtn.frame = CGRectMake(0, 0, 42, 36);
    
    jumpBtn.backgroundColor = [UIColor clearColor];
    
    [jumpBtn addTarget:self action:@selector(jumpSharCar) forControlEvents:UIControlEventTouchUpInside];
    
    [navRit addSubview:imageView];
    
    [navRit addSubview:conutLabel];
    
    [navRit addSubview:jumpBtn];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:navRit];
   
    
}






- (void)jumpSharCar{
    
    ShopCarController *shopVC = [[ShopCarController alloc]init];
    
    shopVC.navigationItem.title = @"购物车";

    shopVC.type = @"goodsDetail";
    
    [self.navigationController pushViewController:shopVC animated:YES];
    
}






- (void)setNav2{
    
    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
    [but setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
    [but setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateHighlighted];
    
    [but addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    
    but.imageView.contentMode = UIViewContentModeScaleAspectFit;
    
    //        but.backgroundColor = [UIColor redColor];
    
    but.frame = CGRectMake(0, 0, 44, 44);
    but.contentEdgeInsets = UIEdgeInsetsMake(11, -10, 11, 22);
    
    UIBarButtonItem *returnButtonItem = [[UIBarButtonItem alloc]initWithCustomView:but];
    
    self.navigationItem.leftBarButtonItem = returnButtonItem;
   
    
}


- (void)back{
    
//     [self.navigationController popViewControllerAnimated:YES];
//
//    return;
    
    UIViewController *temp = nil;
    UIViewController *temp1 = nil;

    for (UIViewController *tmepVC in self.navigationController.childViewControllers) {
        if ([tmepVC isKindOfClass:[OrderSureFirstVC class]]) {
            temp = tmepVC;
        }
        
        if ([tmepVC isKindOfClass:[MeViewController class]]) {
            temp1 = tmepVC;
        }
        
        
    }
    
    
    if (temp != nil) {
    
        
      NSUInteger index = [self.navigationController.childViewControllers indexOfObject:temp];
        
        UIViewController *popVC = [self.navigationController.childViewControllers objectAtIndex:index - 1];
        
        [self.navigationController popToViewController:popVC animated:YES];
        
    } else if (temp1 != nil){
        
        [self.navigationController popViewControllerAnimated:YES];
        
    }else{
        
        [self.navigationController popViewControllerAnimated:YES];

    }
    
    
}




#pragma mark -添加子控制器
- (void)setupAllChildViewController
{
    
    if ([self.type isEqualToString:@"wine"]) {
        MarketHomeController *home = [[MarketHomeController alloc] init];
        home.title = @"首页";
        [self addChildViewController:home];
        
        GoodsCategoryListVC *phone = [[GoodsCategoryListVC alloc] init];
        phone.title = @"手机";
        phone.categoryId = @"3";
        [self addChildViewController:phone];
        
        GoodsCategoryListVC *topLineVc = [[GoodsCategoryListVC alloc] init];
        topLineVc.title = @"电脑";
        topLineVc.categoryId = @"4";
        [self addChildViewController:topLineVc];
        
        GoodsCategoryListVC *hotVc = [[GoodsCategoryListVC alloc] init];
        hotVc.title = @"家电";
        hotVc.categoryId = @"5";
        [self addChildViewController:hotVc];
        
        GoodsCategoryListVC *videoVc = [[GoodsCategoryListVC alloc] init];
        videoVc.title = @"美妆";
        videoVc.categoryId = @"6";
        [self addChildViewController:videoVc];
        
        GoodsCategoryListVC *scoietyVc = [[GoodsCategoryListVC alloc] init];
        scoietyVc.title = @"家居";
        scoietyVc.categoryId = @"7";
        [self addChildViewController:scoietyVc];
        
        GoodsCategoryListVC *readerVc = [[GoodsCategoryListVC alloc] init];
        readerVc.title = @"数码";
        readerVc.categoryId = @"8";
        [self addChildViewController:readerVc];
        

        
    } else {
        
        
//        if ([model.order_status isEqualToString:@"-1"]) {//退款
//            return model.order_item_list.count + 2;
//
//        } else if ([model.order_status isEqualToString:@"0"]){//待付款
//            return model.order_item_list.count + 2;
//
//        }else if ([model.order_status isEqualToString:@"1"]){//待发货
//            return model.order_item_list.count + 2;
//
//        }else if ([model.order_status isEqualToString:@"2"]){//已发货
//            return model.order_item_list.count + 2;
//
//        }else if ([model.order_status isEqualToString:@"3"]){//已收货
//
//            return model.order_item_list.count + 2;
//
//        }else if ([model.order_status isEqualToString:@"5"]){//已关闭
//
//            return model.order_item_list.count + 2;
//
//        }else{//已完成4
//            return 0;
//        }
        
        MyAllOrderListVC *topLineVc = [[MyAllOrderListVC alloc] init];
        topLineVc.title = @"全部";
        [self addChildViewController:topLineVc];
        
        MyAllOrderListVC *readerVc = [[MyAllOrderListVC alloc] init];
        readerVc.title = @"待付款";
        readerVc.status = @"0";
        [self addChildViewController:readerVc];
        
        
        MyAllOrderListVC *hotVc = [[MyAllOrderListVC alloc] init];
        hotVc.title = @"待发货";
        hotVc.status = @"1";

        [self addChildViewController:hotVc];
        
        
        MyAllOrderListVC *videoVc = [[MyAllOrderListVC alloc] init];
        videoVc.title = @"已发货";
        videoVc.status = @"2";

        [self addChildViewController:videoVc];
        
        
        MyAllOrderListVC *scoietyVc = [[MyAllOrderListVC alloc] init];
        scoietyVc.title = @"已收货";
        scoietyVc.status = @"3";

        [self addChildViewController:scoietyVc];
        
        
        MyAllOrderListVC *scienceVc = [[MyAllOrderListVC alloc] init];
        scienceVc.title = @"退货/售后";
        scienceVc.status = @"4";

        [self addChildViewController:scienceVc];
        
    }
    
   
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 
#pragma mark - Navigation
 
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
 
*/

@end
